import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAppStore = defineStore('app', () => {
  // 侧边栏状态
  const sidebarCollapsed = ref(false)
  
  // 主题模式
  const isDarkMode = ref(false)
  
  // 加载状态
  const loading = ref(false)
  
  // 页面标题
  const pageTitle = ref('若依笔记博客')

  // 切换侧边栏
  const toggleSidebar = () => {
    sidebarCollapsed.value = !sidebarCollapsed.value
  }

  // 切换主题
  const toggleTheme = () => {
    isDarkMode.value = !isDarkMode.value
    // 可以在这里添加主题切换逻辑
    document.documentElement.classList.toggle('dark', isDarkMode.value)
  }

  // 设置加载状态
  const setLoading = (status: boolean) => {
    loading.value = status
  }

  // 设置页面标题
  const setPageTitle = (title: string) => {
    pageTitle.value = title
    document.title = title
  }

  return {
    // 状态
    sidebarCollapsed,
    isDarkMode,
    loading,
    pageTitle,
    
    // 方法
    toggleSidebar,
    toggleTheme,
    setLoading,
    setPageTitle
  }
})